<template>
  <div class="c-bg-sgray">
    <div class="c-bg-mb1-orange c-pt60 c-pb64 c-p">
      <span class="user-type-box c-ph20">{{typeMap[userInfo.type]}}</span>
      <div class="c-lh c-fc-white c-pt20 c-fs28 c-ph24">账户余额(元)</div>
      <div class="c-lh c-fc-white c-fs48 c-mt24 c-ph24">{{balance}}</div>
    </div>
    <div class="c-bg-white  c-pv16 c-flex-row">
      <div class="c-w33 c-bd-r1-mgray c-textAlign-c">
        <div class="c-fs24 c-fc-gray">累计收入</div>
        <div class="c-pv16 c-fs30 c-fc-xblack">{{(allMoney*1.0).toFixed(2)}}</div>
      </div>
      <div class="c-w34 c-bd-r1-mgray c-textAlign-c">
        <div class="c-fs24 c-fc-gray">今日收入</div>
        <div class="c-pv16 c-fs30 c-fc-xblack">{{(todayMoney*1.0).toFixed(2)}}</div>
      </div>
      <div class="c-w33 c-textAlign-c">
        <div class="c-fs24 c-fc-gray">本月收入</div>
        <div class="c-pv16 c-fs30 c-fc-xblack">{{(monthMoney*1.0).toFixed(2)}}</div>
      </div>
    </div>
    <div class="c-mt10 c-bg-white">
      <div>
        <div class="c-pv28 c-ph24 c-flex-row c-justify-sb" @click="withdrawBankcard" v-if="!isiOSApp && isBank == 1">
          <span class="c-fs24 c-fc-xblack c-lh">提现到银行卡</span>
          <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
        </div>
        <div class="c-pv28 c-ph24 c-bd-t1 c-flex-row c-justify-sb" @click="withdrawWechat" v-if="!isiOSApp && isWx == 1">
          <span class="c-fs24 c-fc-xblack c-lh">提现到微信钱包</span>
          <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
        </div>
        <div class="c-pv28 c-ph24 c-bd-t1 c-flex-row c-justify-sb" @click="bindBankcard" v-if="!isiOSApp && isBank == 1">
          <span class="c-fs24 c-fc-xblack c-lh">绑定银行卡</span>
          <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
        </div>
      </div>
      <div class="c-pv28 c-ph24 c-bd-t1 c-flex-row c-justify-sb" @click="updatePassword">
        <span class="c-fs24 c-fc-xblack c-lh">修改支付密码</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
    </div>
    <div class="c-mt10 c-bg-white">
      <div class="c-pv28 c-ph24 c-flex-row c-justify-sb" @click="goIncomeDetail">
        <span class="c-fs24 c-fc-xblack c-lh">收入明细</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
      <div v-if="userInfo.type == 3 || userInfo.type == 4" class="c-pv28 c-ph24 c-bd-t1 c-flex-row c-justify-sb" @click="goRecommendList">
        <span class="c-fs24 c-fc-xblack c-lh">推荐记录</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
      <div class="c-pv28 c-ph24 c-bd-t1 c-flex-row c-justify-sb" v-if="!isiOSApp" @click="goWithdraw">
        <span class="c-fs24 c-fc-xblack c-lh">已提现</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
    </div>
    <div class="c-mt10 c-bg-white" v-if="userInfo.type == 1">
      <div class="c-pv28 c-ph24 c-flex-row c-justify-sb" @click="clickOperationsCenter">
        <span class="c-fs24 c-fc-xblack c-lh">运营中心收入</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
    </div>
    <div class="c-mt10 c-bg-white" v-else-if="userInfo.type == 2">
      <div class="c-pv28 c-ph24 c-flex-row c-justify-sb" @click="clickChildForm">
        <span class="c-fs24 c-fc-xblack c-lh">子机构收入</span>
        <span class="icon iconfont c-fs24 c-fc-gray c-block c-hh24">&#xe60e;</span>
      </div>
    </div>

  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js"
export default {
  name: 'FormIndex',
  data() {
    return {
      typeMap: {
        1: '运营中心负责人',
        2: '子机构负责人',
        3: '战略合伙人',
        4: '合伙人',
        5: '暂无身份'
      },
      isiOSApp: false,
      userInfo: {},
      balance: 0,
      monthMoney: 0,
      allMoney: 0,
      todayMoney: 0,
      isBank: 0,
      isWx: 0,
    }
  },
  methods: {
    getFormInfo() {
      utilJs.getMethod(`${global.apiurl}declares`, (res) => {
        if (res.status == -1) {
          this.$routerGo(this, "replace", {
            path: `/error/emptyPage?info=${res.msg}&from=myExam`,
          });
        } else {
          this.isBank = res.setting.isBank;
          this.isWx = res.setting.isWx;
          this.balance = res.balance;
          this.monthMoney = res.monthMoney;
          this.allMoney = res.allMoney;
          this.todayMoney = res.todayMoney;
          this.userInfo = res.customerInfo;
        }
      });
    },
    // 收入明细
    goIncomeDetail() {
      this.$routerGo(this, "push", { path: '/member/taxationForm/recordList' });
    },
    // 推荐记录
    goRecommendList() {
      this.$routerGo(this, "push", { path: '/member/taxationForm/recommendList' });
    },
    // 已提现
    goWithdraw() {
      this.$routerGo(this, "push", { path: '/member/taxationForm/withdrawList' });
    },
    // 修改支付密码
    updatePassword() {
      this.$routerGo(this, "push", { path: '/member/scholarship/updatePassword' });
    },
    // 绑定银行卡
    bindBankcard() {
      this.$routerGo(this, "push", { path: '/member/scholarship/bindBankcard' });
    },
    // 提现到微信钱包
    withdrawWechat() {
      this.$routerGo(this, "push", { path: `/member/scholarship/withdraw?from=wechat&formUserType=${this.userInfo.type}` });
    },
    // 提现到银行卡
    withdrawBankcard() {
      this.$routerGo(this, "push", { path: `/member/scholarship/withdraw?from=bank&formUserType=${this.userInfo.type}` });
    },
    //运营中心收入
    clickOperationsCenter() {
      this.$routerGo(this, "push", { path: `/member/taxationForm/childFormIndex?type=1` });
    },
    //子机构收入
    clickChildForm() {
      this.$routerGo(this, "push", { path: `/member/taxationForm/childFormIndex?type=2` });
    },
    //分享
    wechatShare() {
      utilJs.wechatConfig("", "", "", "", function () { });
    }
  },
  activated() {
    //为了iosAPP审核通过
    this.isiOSApp = navigator.userAgent.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    // 获取我的收益数据
    setDocumentTitle("报单系统");// eslint-disable-line
    this.getFormInfo()
    this.wechatShare();
  },
  deactivated() {

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.user-type-box {
  position: absolute;
  top: 0.75rem;
  right: 0;
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.5rem;
  height: 1rem;
  line-height: 1rem;
  display: flex;
  border-radius: 0.5rem 0px 0px 0.5rem;
  z-index: 99;
}
</style>
